{% include "public/header.html" %}
{% include "public/cmdb_left.html" %}
<div style="float:left;width:900px;margin-left:10px;margin-top:20px;padding-bottom: 80px;">
    <form action="/resources/server/doaddvm" method='post' class="form-horizontal" role="form">
        <div class="form-group">
            <label class="control-label"> >>添加虚拟机</label>
        </div>
        <div class="form-group">
            <label for="inputEmail3" class="col-sm-2 control-label">ST：</label>
            <div class="col-xs-4">
                <input type="text" name="st" class="form-control" placeholder="请填写业务线名称">
            </div>
            <label id="name-st" class="col-sm-4 control-label error"  for="st"></label>
        </div>
        <div class="form-group">
            <label  class="col-sm-2 control-label">资产号：</label>
            <div class="col-xs-4">
                <input type="text" name="assets_no" class="form-control" placeholder="请填写业务线名称">
            </div>
            <label id="name-assets_no" class="col-sm-4 control-label error"  for="assets_no"></label>
        </div>
        <div class="form-group">
            <label  class="col-sm-2 control-label">缩主机：</label>
            <div class="col-xs-4">
                <select name='host' class="form-control">
                    <option value="0">请选择宿主机</option>
                    {% for server in servers %}
                    <option value="{{ server.id }}">{{ server.hostname }}</option>
                    {% endfor %}
                </select>
            </div>
            <button type="button" class="btn btn-link">
                <a href="/resources/server/add" target="_blank" ><span class="glyphicon glyphicon-plus" aria-hidden="true"></span></a>
            </button>
        </div>
        <div class="form-group">
            <label for="inputEmail3" class="col-sm-2 control-label">业务线：</label>
            <div class="col-xs-2">
                <select name='service_id' class="form-control" id="service_id">
                <option value="0">请选择业务线</option>
                {% for product in products %}
                <option value="{{ product.id }}">{{ product.service_name }}</option>
                {% endfor %}
                </select>
            </div>
            <label for="inputEmail3" class="col-sm-2 control-label">产品线：</label>
            <div class="col-xs-2">
                <select name='server_purpose' class="form-control" id="server_purpose">
                <option value="0">请选择产品</option>
                </select>
            </div>
            <button type="button" class="btn btn-link">
                <a href="/resources/server/addproduct" target="_blank" ><span class="glyphicon glyphicon-plus" aria-hidden="true"></span></a>
            </button>
        </div>
        <div class="form-group">
            <label  class="col-sm-2 control-label">服务器状态：</label>
            <div class="col-xs-4">
                <select name='status' class="form-control">
                    <option value="0">请选择服务器状态</option>
                    {% for status in service_status %}
                    <option value="{{ status.id }}">{{ status.name }}</option>
                    {% endfor %}
                </select>
            </div>
            <button type="button" class="btn btn-link">
                <a href="/resources/server/addstatus" target="_blank" ><span class="glyphicon glyphicon-plus" aria-hidden="true"></span></a>
            </button>
        </div>
        <div class="form-group">
            <label class="col-sm-2 control-label">主机名：</label>
            <div class="col-xs-4">
                <input type="text" name="hostname" class="form-control" placeholder="请输入主机名">
            </div>
            <label id="name-hostname" class="col-sm-4 control-label error"  for="hostname"></label>
        </div>
        <div class="form-group">
            <label class="col-sm-2 control-label">ip地址：</label>
            <div class="col-xs-2">
                <input type="text" name="ip" class="form-control" placeholder="请输入ip">
            </div>
            <label style="padding-left:0px;width:40px;padding-right:0px;"  class="col-sm-2 control-label">网口:</label>
            <div class="col-xs-2" style="width:110px;padding-right:0px;" >
                <select name='device' class="form-control">
                    <option value="eth0">eth0</option>
                    <option value="eth1">eth1</option>
                    <option value="eth2">eth2</option>
                    <option value="eth3">eth3</option>
                    <option value="manage">manage</option>
                </select>
            </div>
            <label style="padding-left:0px;width:80px;padding-right:0px;"   class="col-sm-2 control-label">MAC地址:</label>
            <div class="col-xs-2">
                <input type="text" name="mac" class="form-control" placeholder="请输入MAC地址">
            </div>

        </div>

        <div class="form-group">
            <label  class="col-sm-2 control-label">备注：</label>
            <div class="col-xs-6">
                <textarea class="form-control" name="remark" rows="3"></textarea>
            </div>
        </div>
        <div class="form-group">
            <div class="col-sm-offset-2 col-sm-10">
                <input type="hidden" name="vm_status" value="0">
                <button type="submit" class="btn btn-primary">添加</button>
            </div>
        </div>
    </form>
</div>
{% include "public/footer.html" %}
<script>
$(function(){

    $("#service_id").change(function(){
        var pid = $(this).val();
        if(pid != 0){
            $.get("/api/ajax/get-server-product",{pid:pid},function(data){
                var html = '<option value="0">请选择主品线</option>';
                for (x in data) {
                    html += "<option value='"+data[x].id+"'>"+data[x].service_name+"</option>"
                }
                $("#server_purpose").html(html)
             },"json");
        }else{
             $("#server_purpose").html('<option value="0">请选择业务</option>')
        }
    });

    // ip name change
    $('.ip_info').change(function(){
        var sel_obj = $(this);
        var select_val = sel_obj.val();
        var option_objs = sel_obj.find('option');
         $.each(option_objs,function(n,value) {
             var new_obj = $(value);
             if(select_val == new_obj.val()){
                 var new_val = new_obj.attr('data');
                 $('#ip_type').val(new_val)
             }

         })

    })
})
</script>
